<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/pages/common/component.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>文档管理</title>

<script language="javascript">
var oprateAction = "feeAction.do";

function viewArc(aid){
	if(aid==0) aid = getOneItem();
	window.open("archives.asp?aid="+aid+"&action=viewArchives");
}
function editArc(aid){
	if(aid==0) aid = getOneItem();
	location="archives.asp?aid="+aid+"&action=editArchives";
}
function updateArc(aid){
	var qstr=getCheckboxItem();
	if(aid==0) aid = getOneItem();
	location="archives.asp?aid="+aid+"&action=makeArchives&qstr="+qstr+"";
}
function checkArc(aid){
	var qstr=getCheckboxItem();
	if(aid==0) aid = getOneItem();
	location="archives.asp?aid="+aid+"&action=checkArchives&qstr="+qstr+"";
}
function moveArc(aid){
	var qstr=getCheckboxItem();
	if(aid==0) aid = getOneItem();
	location="archives.asp?aid="+aid+"&action=moveArchives&qstr="+qstr+"";
}
function adArc(aid){
	var qstr=getCheckboxItem();
	if(aid==0) aid = getOneItem();
	location="archives.asp?aid="+aid+"&action=commendArchives&qstr="+qstr+"";
}
// 删除选中的记录
function delFee(){
	$("#method").val("delete");
	var cbFeeIds = $('input:checked')
	if(cbFeeIds.length == 0){
		alert("请选择要删除的数据!");
		return ;
	}
	if(confirm('确定将选择的'+cbFeeIds.length+'条记录删除吗?')){
		$("#feeForm").submit();
	}
}

//获得选中文件的文件名
function getCheckboxItem()
{
	var allSel="";
	if(document.form2.feeId.value) return document.form2.feeId.value;
	for(i=0;i<document.form2.feeId.length;i++)
	{
		if(document.form2.feeId[i].checked)
		{
			if(allSel=="")
				allSel=document.form2.feeId[i].value;
			else
				allSel=allSel+"`"+document.form2.feeId[i].value;
		}
	}
	return allSel;
}

//获得选中其中一个的id
function getOneItem()
{
	var allSel="";
	if(document.form2.id.value) return document.form2.id.value;
	for(i=0;i<document.form2.id.length;i++)
	{
		if(document.form2.id[i].checked)
		{
				allSel = document.form2.id[i].value;
				break;
		}
	}
	return allSel;
}
function selAll()
{
	$("input[name='feeIds']").each(function(){
    	$(this).attr("checked",true);
    });
}
function noSelAll()
{
	$("input[name='feeIds']").each(function(){
    	$(this).attr("checked",false);
    });
}
// 新增
function addFee(feeType){
	window.location.href="/venus/"+oprateAction+"?method=create&feeType="+feeType;
}
// 编辑
function editFee(feeId){
	window.location.href="/venus/"+oprateAction+"?method=edit&feeId="+feeId;
}

$(document).ready(function(){
	// 修改数据变色
	var updateFeeId = '<c:out value="${updateFeeId}"/>';
	if(updateFeeId){
		$("#fee_"+updateFeeId).css("background","#F570A5");
		$("#fee_"+updateFeeId).attr("onMouseMove","");
		$("#fee_"+updateFeeId).attr("onMouseOut","");
	}
	
	// 新增数据变色
	var newFeeId = '<c:out value="${newFeeId}"/>';
	if(newFeeId){
		$("#fee_"+newFeeId).css("background","#8080E6");
		$("#fee_"+newFeeId).attr("onMouseMove","");
		$("#fee_"+newFeeId).attr("onMouseOut","");
	}
	// 校验主表单
   	$("#feeForm").validationEngine();
	
	getAllAccount2Element("accountId", "<c:out value="${feeForm.accountId}"/>");
  	configDate("startDate", "<c:out value="${feeForm.startDate}"/>", 'yy-mm-dd');
  	configDate("endDate", "<c:out value="${feeForm.endDate}"/>", 'yy-mm-dd');
	
	// 处理查询费用类型
  	var feeType = '<c:out value="${feeForm.feeType}"/>';
  	var feeTypeId = '<c:out value="${feeForm.feeTypeId}"/>';
  	var feeSubTypeId = '<c:out value="${feeForm.feeSubTypeId}"/>';
  	if(feeType != <%=Constants.FEE_TYPE_ALL%>){ // 类型不是所有的
  		getFeeType(feeType, 'feeTypeId', 'feeSubTypeId', feeTypeId); // 填充feeTypeId
  		if(feeTypeId != 0){ // 费用类型不是所有,填充费用子类
  			getFeeSubType(feeTypeId, 'feeSubTypeId', feeSubTypeId); // 填充feeSubTypeId
  		}
  	}
});


// 将费用类型的添加到页面select元素中
function getFeeType(feeType, feeTypeId, feeSubTypeId, value){
	$.ajax({
	    url: 'feeTypeAction.do?method=getFeeType4Ajax&feeType='+feeType,
	    type: 'GET',
	    dataType: 'json',
	    cache: false,
		async: false,
	    error: function(){
	        alert('查询费用类型出错!');
	    },
	    success: function(json){
			// 清空费用类型
	    	var feeTypeOptions = $("#"+feeTypeId+" option:gt(0)");
	    	$.each(feeTypeOptions, function(){
				$(this).remove();
			});
			// 清空费用子类
			var feeSubTypeOptions = $("#"+feeSubTypeId+" option:gt(0)");
	    	$.each(feeSubTypeOptions, function(){
				$(this).remove();
			});
	    	$.each(json,function(idx,obj){
				var isSelected = '';
				if(value == obj.feeTypeId){
					isSelected = 'selected';
				}
	    		$("#"+feeTypeId).append("<option value='"+obj.feeTypeId+"' "+isSelected+">"+obj.feeTypeName+"</option>");
	    	})
	    	//$("#"+feeTypeId).attr("style","width:30%");
	    }
	});
}

// 将费用子类型的添加到页面select元素中
function getFeeSubType(feeTypeId, feeSubTypeId, value){
	$.ajax({
	    url: 'feeTypeAction.do?method=getFeeSubType4Ajax&feeTypeId='+feeTypeId,
	    type: 'GET',
	    dataType: 'json',
	    cache: false,
		async: false,
	    error: function(){
	        alert('查询费用子类出错!');
	    },
	    success: function(json){
	    	var feeSubTypeOptions = $("#"+feeSubTypeId+" option:gt(0)");
	    	$.each(feeSubTypeOptions, function(){
				$(this).remove();
			})
	    	$.each(json,function(idx,obj){
				var isSelected = '';
				if(value == obj.feeTypeId){
					isSelected = 'selected';
				}
	    		$("#"+feeSubTypeId).append("<option value='"+obj.feeTypeId+"' "+isSelected+">"+obj.feeTypeName+"</option>");
	    	})
	    	//$("#"+feeTypeId).attr("style","width:30%");
	    }
	});
}

function queryFee(){
	// 重置分页信息
	$("#curPage").val(1);
	$('#method').val('list');
	$('#feeForm').submit();
}
</script>
</head>
<body leftmargin="8" topmargin="8" background='pages/desktop/skin/images/allbg.gif'>
<!--  内容列表   -->
<html:form method="post" styleId="feeForm" action="feeAction.do">
	<input type="hidden" id="method" name="method" value=""/>

<table width='98%' border='0' cellpadding='1' cellspacing='1' bgcolor='#CBD8AC' align="center" style="margin-top:8px" background='pages/desktop/skin/images/wbg.gif'>
  <tr bgcolor='#EEF4EA'>
    <td align='left'>
    	费用类型:
    	<select name="feeType" onchange="getFeeType(this.value, 'feeTypeId', 'feeSubTypeId', '')">
    		<option value="<%=Constants.FEE_TYPE_ALL%>" ${feeForm.feeType==2 ? 'selected' : ''}>全部</option>
    		<option value="0" ${feeForm.feeType==0 ? 'selected' : ''}>支出</option>
    		<option value="1" ${feeForm.feeType==1 ? 'selected' : ''}>收入</option>
    	</select>
    	&nbsp;&nbsp;
    	费用类别:
    	<select id="feeTypeId" name="feeTypeId" onchange="getFeeSubType(this.value, 'feeSubTypeId', '')" style='width:60px;'>
    		<option value="0">所有</option>
    	</select>
    	&nbsp;&nbsp;
    	费用子类:
    	<select id="feeSubTypeId" name="feeSubTypeId" style='width:60px;'>
    		<option value="0">所有</option>
    	</select>
    	&nbsp;&nbsp;
    	操作账户:
    	<select id="accountId" name="accountId" style='width:100px;'>
    		<option value="0">所有</option>
    	</select>
    	&nbsp;&nbsp;
    	时间范围:
    	<input id="startDate" name="startDate" readonly="readonly" style='width:80px;'/>至<input id="endDate" name="endDate" readonly="readonly" style='width:80px;'/>
    	&nbsp;&nbsp;
    	金额范围:
    	<input id="minAmount" name="minAmount" class="validate[custom[number]]" style='width:60px;' value="${feeForm.minAmount!=0?feeForm.minAmount:''}"/>至<input id="maxAmount" name="maxAmount" class="validate[custom[number]]" style='width:60px;' value="${feeForm.maxAmount!=0?feeForm.maxAmount:''}"/>
    	&nbsp;&nbsp;
    	<button onclick="queryFee()">查询</button>
    </td>
  </tr>
</table>

<table width="98%" border="0" cellpadding="2" cellspacing="1" bgcolor="#D1DDAA" align="center" style="margin-top:8px">
<tr bgcolor="#E7E7E7">
	<td height="24" colspan="12" background="pages/desktop/skin/images/tbg.gif">&nbsp;文档列表&nbsp;</td>
</tr>
<tr align="center" bgcolor="#FAFAF1" height="22">
	<th width="3%"></th>
	<th width="6%">编号</th>
	<th width="10%">消费者</th>
	<th width="10%">类型</th>
	<th width="10%">账户</th>
	<th width="10%">费用类型</th>
	<th width="10%">费用子类</th>
	<th width="10%">日期</th>
	<th width="8%">金额</th>
	<th width="6%">退回</th>
	<th width="10%">备注</th>
	<th width="15%">操作</th>
</tr>
<c:forEach var="feeVO" items="${lstFeeVOs}" varStatus="i">
	<tr id="fee_${feeVO.feeId }" align='center' bgcolor="#FFFFFF" onMouseMove="javascript:this.bgColor='#FAFAF1';" onMouseOut="javascript:this.bgColor='#FFFFFF';" height="22" >
		<td><input name="feeIds" type="checkbox" value="${feeVO.feeId }" class="np"></td>
		<td>${feeVO.feeId }</td>
		<td>${feeVO.pubUser.name }</td>
		<td>${feeVO.feeType.feeType==0 ? '<font color="red">支出</font>' : '<font color="green">收入</font>' }</td>
		<td>${feeVO.account.accountName }</td>
		<td>${feeVO.feeType.feeTypeName }</td>
		<td>${feeVO.feeSubType.feeTypeName }</td>
		<td><fmt:formatDate value="${feeVO.feeDate }" pattern="yyyy年MM月dd日"/></td>
		<td>${feeVO.amount}</td>
		<td>
			<c:if test="${feeVO.isReturn == 0}">
				不可退回
			</c:if>
			<c:if test="${feeVO.isReturn == 1}">
				可以退回
			</c:if>
		</td>
		<td>${feeVO.note }</td>
		<td><a href="#" onclick="editFee('${feeVO.feeId }');">编辑</a></td>
	</tr>
</c:forEach>
<tr bgcolor="#EEF4EA">
	<td align="left" height="28" colspan="4">
		<a href="javascript:selAll()" class="coolbg">全选</a>
		<a href="javascript:noSelAll()" class="coolbg">取消</a>
		<a href="javascript:addFee(0)" class="coolbg">新增支出</a>
		<a href="javascript:addFee(1)" class="coolbg">新增收入</a>
		<a href="javascript:delFee()" class="coolbg">&nbsp;删除&nbsp;</a>
	</td>
	<td align="right" height="28" colspan="8">
		<venus:splitPage name="objPageInfo" formId="feeForm"/>
	</td>
</tr>
</table>
</html:form>
</body>
</html>